home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / source / music4c.sit / Music4C Folder / orchestras / ReadSD_1_File.c < prev    next >
Text File  |  1990-09-11  |  3KB  |  129 lines

  1. /* this instrument just reads in a Sound Designer¬ format sound file
  2. and outputs it as a stereo file.
  3. */
  4. /*
  5. * ⌐ Graeme Gerrard 1990
  6. * Faculty of Music, University of Melbourne
  7. * Parkville Victoria 3052 Australia.
  8. *
  9. * ARPANET: grae@murdu.ucs.unimelb.edu.au
  10. * telephone: (613) 344 4127, Fax: (613) 344 5104
  11. */
  12.  
  13.  
  14.  
  15. #define    READTYPE    1    /* type of instrument */
  16.  
  17. #include    <math.h>
  18. #include    "Music4c.h"
  19. #include    "ugens.h"
  20. #include    "orch.h"
  21. #include    "Music4C_Prototype.h"
  22.  
  23.  
  24. static    double E_buf[512];
  25. static    int    E_buflen;
  26. static    double    E_ptr;
  27. static    double    E_si;
  28. static    double    InSig;
  29. static    double    OutSig;
  30. static    ParmBlkPtr    E_myPBlkPtr;
  31. static    ParamBlockRec        E_myPBlk;
  32. static    long StartSamp, EndSamp;
  33. static    double SampPtr;
  34.  
  35. Boolean    SetSFDir(Str255, long *);
  36. extern    long    SoundFileDirID;
  37. extern    Str255    SFDirectoryName;
  38. extern    Str255    theMess1;
  39. extern    OSErr    theErr;
  40. extern    DialogPtr    thePass3DialogPtr;
  41. extern    void    DisplayDialog(DialogPtr);
  42.  
  43.  
  44.  
  45. void initl()
  46. {
  47.  
  48.     Point    where;
  49.     SFTypeList    types;
  50.     SFReply        theFileReply;
  51.     long        nBytes;
  52.  
  53.     E_buflen = 512;
  54.     E_myPBlkPtr = &E_myPBlk;
  55.     
  56.     /* set up soundfile directory*/
  57.     SetSFDir(SFDirectoryName, &SoundFileDirID);
  58.     
  59.     SetPt(&where, 100, 100);
  60.     types[0] = 'SFIL';
  61.     SFGetFile(where, NIL, NIL, 1, types, NIL, &theFileReply);
  62.     if(!theFileReply.good) {
  63.         FixUp();
  64.         CleanUp(FALSE);
  65.     }
  66.     DisplayDialog(thePass3DialogPtr);
  67.     E_myPBlkPtr->ioParam.ioNamePtr = (StringPtr)theFileReply.fName;
  68.     E_myPBlkPtr->ioParam.ioVRefNum = NIL;
  69.     E_myPBlkPtr->ioParam.ioVersNum = NIL;
  70.     E_myPBlkPtr->ioParam.ioPermssn = fsRdPerm;
  71.     theErr = PBOpen(E_myPBlkPtr, FALSE);
  72.     if ( theErr != noErr ) {
  73.         PstringCopy((char *)theMess1, "\pError opening file");
  74.         OSError(theMess1, theFileReply.fName, theErr);
  75.     }
  76.  
  77.     E_myPBlkPtr->ioParam.ioCompletion = NIL;
  78.     PBGetEOF(E_myPBlkPtr, FALSE);
  79.     nBytes = (long)E_myPBlkPtr->ioParam.ioMisc;
  80. }
  81.  
  82. void setup()
  83. {
  84.  
  85.     switch( instype ) {
  86.         case    READTYPE:
  87.  
  88.             E_si = p[4];                    /* sample increment */
  89.             SampPtr = p[5];        /* start sample in file */
  90.             StartSamp = (long)SampPtr;
  91.             if ( !SF_SD_1_ReadSet( E_buf, E_buflen, &E_ptr, E_myPBlkPtr, &SampPtr, &StartSamp, &EndSamp) ) {
  92.                 fprintf(stderr,"bad file name?\n");
  93.             }
  94.             OutSig = 0.0;
  95.             InSig = 0.0;
  96.             break;
  97.         default:
  98.             fprintf(stderr, "Wrong file type\n");
  99.     }
  100.  
  101. }
  102.  
  103. void orch()
  104. {
  105.     switch( instype ) {
  106.         case    READTYPE:
  107.             InSig = SF_SD_1_Read(E_myPBlkPtr, E_si, E_buf, E_buflen, &E_ptr, &SampPtr, &StartSamp, &EndSamp);
  108.             OutSig = InSig;
  109. /*            mono(OutSig);*/
  110.             Stereo(OutSig, 0.5);
  111.             break;
  112.         default:
  113.             fprintf(stderr, "Wrong instrument type\n");
  114.     }
  115. }
  116. void    ter()
  117. {
  118. }
  119.  
  120.  
  121.  
  122. void final()
  123. {
  124. /* called at the end of the synth run.
  125. *  close any files etc. you haven't already closed here.
  126. */
  127.     PBClose(E_myPBlkPtr, FALSE);
  128. }
  129.